#include<math.h>
#include <iostream>
#include <map>
using namespace std;
struct stu {
    int e;
    double c;
};
int main() {
    int n, m, a;
    cin >> n;
    double b;
    map<int, double> map;
    int maxA;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        map[a] = b;
        if (i == 0) maxA = a;
    }
    cin >> m;
    stu x[m], q[m];
    for (int i = 0; i < m; i++) {
        cin >> x[i].e >> x[i].c;
    }
    int p = 0;
    while (maxA >= x[0].e) {
        int f = maxA - x[0].e;
        double ff = map[maxA] / x[0].c;
        if (fabs(ff) >= 0.05) {
            q[p].e = f;
            q[p++].c = ff;
            for (int i = 0; i < m; i++) {
                map[x[i].e + f] -= x[i].c * ff;
            }
        }
        else maxA--;
        while (maxA >= x[0].e && fabs(map[maxA]) < 0.05) maxA--;
    }
    cout << p;
    if (!p) cout << " 0 0.0\n";
    else {
        for (int i = 0; i < p; i++) {
            printf(" %d %.1f", q[i].e, q[i].c);
        }
        cout << endl;
    }
    p = 0;
    while (maxA >= 0) {
        if (fabs(map[maxA]) >= 0.05) {
            q[p].e = maxA;
            q[p++].c = map[maxA];
        }
        maxA--;
    }
    cout << p;
    if (!p) cout << " 0 0.0\n";
    for (int i = 0; i < p; i++) {
        printf(" %d %.1f", q[i].e, q[i].c);
    }
    return 0;
}